#ifndef UNREALMAP_H
#define UNREALMAP_H

#include "routemap.h"
#include "unrealstream.h"
#include "main.h"

using namespace Gio;
using namespace std;
using namespace Glib;
using namespace vectorMap;

struct UnrealNodeId:public NodeId{
    int category;
    UnrealNodeId(int cat=0, int i=0):NodeId(i){
        category= cat;
    }
    virtual bool operator==(UnrealNodeId other){
        return (other.id==id) && (other.category==category);
    }
    virtual UnrealNodeId operator=(UnrealNodeId other){
        id=other.id;
        category=other.category;
        return *this;
    }
};



struct UnrealPlace:Place{
        /**parse frwom comma sep. value
        */
    UnrealPlace( char* str);
    UnrealPlace( string str);
    void parse( char* str);
    void parse( string str);
    UnrealPlace(UnrealPlace* newp){
		x=newp->x;
		y=newp->y;
		z=newp->z;
	}
	UnrealPlace(UnrealPlace& newp){
		x=newp.x;
		y=newp.y;
		z=newp.z;
	}
    UnrealPlace(){};
    operator ustring(){
         return ustring::compose("%1.%2", x/100, x%100) + ","
              + ustring::compose("%1.%2", y/100, y%100) + ","
              + ustring::compose("%1.%2", z/100, z%100) ;
    }
    ustring toString(){
         return ustring::compose("%1.%2", x/100, x%100) + ","
              + ustring::compose("%1.%2", y/100, y%100) + ","
              + ustring::compose("%1.%2", z/100, z%100) ;
    }
    virtual double lengthSquare(Place* to);
    int z;//add z component
	virtual UnrealPlace& operator= (UnrealPlace* newp){
		x=newp->x;
		y=newp->y;
		z=newp->z;
		return *this;
	}
	virtual UnrealPlace& operator= (UnrealPlace& newp){
		x=newp.x;
		y=newp.y;
		z=newp.z;
		return *this;
	}
};

struct UnrealPath:Path{
    UnrealNodeId fromId;
    UnrealNodeId toId;
    int collisionH, collisionR;
    unsigned flags;
    UnrealPath(UnrealNodeId f, UnrealNodeId t):fromId(f), toId(t){}

    UnrealPath(int fcat=0, int fid=0, int tcat=0, int tid=0):fromId(fcat, fid), toId(tcat, tid){}

};



class UnrealMap: public RouteMap{
    public:
        Mutex mutex;
        int zMax, zMin;
        /** Default constructor */
        UnrealMap();
        void readInput(UnrealStream& input);
        /** Default destructor */
        virtual ~UnrealMap();

        Node* **lookupTable;//2d array; first the category, then the id
		virtual void finalize();

        int nodeCount(){
            return nodes.size();
        }
		virtual void invalidate();
    protected:

    /**readInputSNGP
     *reads the input from the SNAV command.
     */

    void readInputSNGP(UnrealStream& input, Node* node);
private:
    vector<string> prefixes;/** the list of possible prefixes the nodes can have;*/
    vector<int>    prefixCounts;/**the amount of nodes in each category(prefix)*/

};

#endif // UNREALMAP_H
